﻿<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
	<head>
		<meta charset="UTF-8">
		<title>小米6立即购买-小米商城</title>
		<link rel="stylesheet" type="text/css" href="css/style.css">
		<%-- 引入JQ和Bootstrap--%>
		<!--<link href="assets/css/bootstrap.css" rel="stylesheet">-->
		<style>
			.left img{
				width: 550px;
				height: 550px;
			}
		</style>
	</head>

	<script src="js/jquery/2.0.0/jquery.min.js"></script>

	<script src="js/bootstrap/3.3.6/bootstrap.min.js"></script>
	<body>
	<!-- start header -->
	<jsp:include page="include/top.jsp"></jsp:include>
	<!--end header -->

<!-- start banner_x -->
	<jsp:include page="include/seacher.jsp"></jsp:include>
<!-- end banner_x -->

	
	<!-- xiangqing -->

	<div class="xiangqing">
		<div class="neirong w">
			<div class="xiaomi6 fl">${product.name}</div>
			<nav class="fr">
				<li><a href="">概述</a></li>
				<li>|</li>
				<li><a href="">变焦双摄</a></li>
				<li>|</li>
				<li><a href="">设计</a></li>
				<li>|</li>
				<li><a href="">参数</a></li>
				<li>|</li>
				<li><a href="">F码通道</a></li>
				<li>|</li>
				<li><a href="">用户评价</a></li>
				<div class="clear"></div>
			</nav>
			<div class="clear"></div>
		</div>	
	</div>
	
	<div class="jieshao mt20 w">
		<div class="left fl"><img src="${path}/${product.id}.jpg"></div>
		<div class="right fr">
			<div class="h3 ml20 mt20">${product.name}</div>
			<div class="jianjie mr40 ml20 mt10"></div>
			<div class="jiage ml20 mt10">${product.price}元</div>
			<div class="ft20 ml20 mt20">选择版本</div>
			<div class="xzbb ml20 mt10">
				<div class="banben fl">
					<a>
						<span>${product.subTitle} </span>
						<span>${product.price}</span>
					</a>
				</div>

				<div class="clear"></div>
			</div>

			<div class="xzbb ml20 mt10">
				<div class="productNumber">
					<span>数量</span>
					<span>
					<span class="productNumberSettingSpan">
					<input type="text" id="number" value="1" class="productNumberSetting">
					</span>
						<span class="arrow">
						<a class="increaseNumber" href="#nowhere">
						<span class="updown">
						   <img src="image/fore/increase.png">
						</span>
						</a>
						<span class="updownMiddle"> </span>
						<a class="decreaseNumber" href="#nowhere">
							<span class="updown">
							<img src="image/fore/decrease.png">
						</span>
						</a>
						</span>
						件</span>
				<tr></tr>
					<span>库存${product.stock}件</span>
				</div>
			</div>
			<div class="xqxq mt20 ml20">
				<div class="top1 mt10">
					<div class="left1 fl">${product.subTitle}</div>
					<div class="clear"></div>
				</div>
				<div class="bot mt20 ft20 ftbc">总计：${product.price}</div>
			</div>
			<div class="xiadan ml20 mt20">


					<input class="jrgwc"  style="width: 120px" type="button" onclick="addCartLink()" name="jrgwc" value="加入购物车" />
				<a onclick="javascript:buyLink()" class="buyLink">
					<input class="jrgwc"  style="width: 120px" type="button" name="jrgwc" value="立即选购" />
				</a>
				<c:if test="${user!=null}">
					<c:if test="${collection==null}">
						<input class="jrgwc" style="width: 120px" type="button" name="jrgwc" onclick="addcollectionLink()" value="收藏" />
					</c:if>
					<c:if test="${collection==1}">
						<input class="jrgwc" style="color: grey;width: 120px"  type="button" name="jrgwc" onclick="" value="收藏" />
					</c:if>
				</c:if>
			</div>

			</div>
		<div class="clear"></div>
	</div>

	<!-- footer -->
	<footer class="mt20 center">
			
			<div class="mt20">小米商城|MIUI|米聊|多看书城|小米路由器|视频电话|小米天猫店|小米淘宝直营店|小米网盟|小米移动|隐私政策|Select Region</div>
			<div>©mi.com 京ICP证110507号 京ICP备10046444号 京公网安备11010802020134号 京网文[2014]0059-0009号</div> 
			<div>违法和不良信息举报电话：185-0130-1238，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试</div>

		</footer>
<script type="text/javascript">

	function buyLink() {
		var page = "/checkLogin";
		$.get(
				page,
				function (result) {
					if ("success" == result) {
						location.href="/buyone?product_id="+${product.id}+"&number=" + $("#number").val()
					}
					else {
						alert("未登录，请先登录！")
					}
				}
		);
	}


	function addCartLink() {
       var page = "/checkLogin";
        $.get(
            page,
            function (result) {
                if ("success" == result) {
                    var product_id = ${product.id};
                     var num = $(".productNumberSetting").val();
                    var addCartpage = "/addCart";
                    $.get(
                        addCartpage,
                        {"product_id": product_id, "num": num},
                        function (result) {
                            if ("success" == result) {
                                $(".addCartButton").html("已加入购物车");
                                $(".addCartButton").attr("disabled", "disabled");
                                $(".addCartButton").css("background-color", "lightgray");
                                $(".addCartButton").css("border-color", "lightgray");
                                $(".addCartButton").css("color", "black");
                                alert("购物车加入成功!");
                            }
                            else {
                            }
                        }
                    );
                }
                else {
                  alert("未登录，请先登录！")
                }
            }
        );
        return false;
    }
   var stock = ${product.stock};
   $(".productNumberSetting").keyup(function () {
       var num = $(".productNumberSetting").val();
       num = parseInt(num);
       if (isNaN(num))
           num = 1;
       if (num <= 0)
           num = 1;
       if (num > stock)
           num = stock;
       $(".productNumberSetting").val(num);
   });

   $(".increaseNumber").click(function () {
       var num = $(".productNumberSetting").val();
       num++;
       if (num > stock)
           num = stock;
       $(".productNumberSetting").val(num);
   });
   $(".decreaseNumber").click(function () {
       var num = $(".productNumberSetting").val();
       --num;
       if (num <= 0)
           num = 1;
       $(".productNumberSetting").val(num);
   });

   $("div.productReviewDiv").hide();
   $("a.productDetailTopReviewLink").click(function () {
       $("div.productReviewDiv").show();
       $("div.productDetailDiv").hide();
   });
   $("a.productReviewTopPartSelectedLink").click(function () {
       $("div.productReviewDiv").hide();
       $("div.productDetailDiv").show();
   });

       function CartLink() {
           var page = "/checkLogin";
           $.get(
               page,
               function (result) {
                   if ("success" == result) {
                       location.href="/Cart"
                   }
                   else {
                       alert("未登录，请先登录！")
                   }
               }
           );
           return false;
       }

   function addcollectionLink() {
       var page = "/checkLogin";
       $.get(
           page,
           function (result) {
               if ("success" == result) {
                   location.href="/shoucang?product_id=${product.id}"
               }
               else {
                   alert("未登录，请先登录！")
               }
           }
       );
       return false;
   }
//
</script>
	</body>
</html>